package br.com.projetoquestao.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import br.com.projetoquestao.model.Questao;
import br.com.projetoquestao.repository.QuestaoRepository;

@Controller
public class QuestaoController {

	@Autowired
	private QuestaoRepository repository;

	@RequestMapping(value = "/questoes", method = RequestMethod.GET)
	@ResponseBody
	public List<Questao> getQuestoes() {
		return repository.getQuestoes();
	}

	@RequestMapping(value = "/questoes/{id}", method = RequestMethod.POST)
	@ResponseBody
	public void fazerPedido(@RequestBody Questao questaoRequisicao, @PathVariable Long id) {
		Questao questao = repository.getItem(id);
		repository.salvarPedido(questao);
	}

}
